/*
 * Copyright (c) 2011 Ondrej Lapacek
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

/**
 * @author      Ondrej Lapacek
 * @version     1.0, 09/12/11
 * @since       1.0
 */

package cz.muni.fi.android.assistivecamera.hardware;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import cz.muni.fi.android.assistivecamera.R;
import cz.muni.fi.android.assistivecamera.dialog.BlindDialog;
import cz.muni.fi.android.assistivecamera.dialog.ResponseEventListener;
import cz.muni.fi.android.assistivecamera.texttospeech.SpeechHandler;

public class HardwareFeatures implements ResponseEventListener {
	
	private Context ctx;
	
	private BlindDialog customizeDialog = null;

    public HardwareFeatures(Context context) {
    	
    	ctx = context;
    	
    	if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
    		String hardware = ctx.getResources().getString(R.string.hardwareCamera);
    		SpeechHandler.ttsQueue(hardware, 1, 1);
    		builtDismissDialog(hardware);
    	}

    	if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)) {
     		String hardware = ctx.getResources().getString(R.string.hardwareGPS);
    		SpeechHandler.ttsQueue(hardware, 1, 1);
    		builtDismissDialog(hardware);
    	}
    			
    	if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)) {
    		String hardware = ctx.getResources().getString(R.string.hardwareAcc);
    		SpeechHandler.ttsQueue(hardware, 1, 1);
    		builtDismissDialog(hardware);
    	}
    }
    
    private void builtDismissDialog(String hardware) {
    	String title = ctx.getResources().getString(R.string.hardwareStatus);
    	title = title + ": " + hardware;
    	String[] names = {ctx.getResources().getString(R.string.exitAppDialog)};
        customizeDialog = new BlindDialog(ctx, HardwareFeatures.this, title, names);
        customizeDialog.setCancelable(false);
        customizeDialog.show();
    }

	@Override
	public void responseEvent(String response) {
		customizeDialog.hide();
		customizeDialog.dismiss();
		if (response.equals(ctx.getResources().getString(R.string.exitAppDialog))) {
			((Activity) ctx).finish();
		}
	}
}
